using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BuildTimerAddIn.Configuation
{
    public partial class BuildTimerOptions : Form
    {
        private Settings m_Set;

        public BuildTimerOptions()
        {
            InitializeComponent();
            m_Set = Settings.Default;

            cbTotalTime.Checked = m_Set.TotalBuildTime;
            cbPerProject.Checked = m_Set.PerProjectBuildTimes;
            cbIgnoreShortProjects.Checked = m_Set.IgnoreShortProjects;
            textShortProjectDuration.Text = m_Set.ShortProjectDuration.ToString();
            textShortProjectDuration.Enabled = m_Set.IgnoreShortProjects;

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            m_Set.TotalBuildTime = cbTotalTime.Checked;
            m_Set.PerProjectBuildTimes = cbPerProject.Checked;
            m_Set.IgnoreShortProjects = cbIgnoreShortProjects.Checked;

            uint shortProjectDuration = 0;
            if (!uint.TryParse(textShortProjectDuration.Text, out shortProjectDuration))
            {
                textShortProjectDuration.ForeColor = Color.Red;
                textShortProjectDuration.Focus();
                return;
            }
            m_Set.ShortProjectDuration = shortProjectDuration;

            m_Set.Save();
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cbIgnoreShortProjects_CheckedChanged(object sender, EventArgs e)
        {
            textShortProjectDuration.Enabled = cbIgnoreShortProjects.Checked;
        }
    }
}